<?php
include('/controller/vytvor.php');
include('/model/kategoriahodnotenia.php');
class kategoriahodnotenia extends vytvor{ 
        
       public function handle($action){
			switch ($action){
				case 'vytvor':
					return parent::handle($action);
					break;
				case 'uprav':
					if (isset($_SESSION["idupravkathod"])){
						return parent::handle($action);
						break;
					} else {
						return view::load('error404', array());
						break;
					}
					
				case 'vypis':
					if (isset($_SESSION["idupravkathod"])) {unset($_SESSION["idupravkathod"]);}
					if (isset($_POST["pridat"])){ 
						 if ($this->meno_check($_POST["autocomplete"])) {$this->pridaj($_POST["autocomplete"], $_POST["kategoriupridaj"]);}
					}
					if (isset($_POST['odstran'])){
						$this->odstran($_POST['kategoriahodnotenia']);		
					}
					if (isset($_SESSION["idupravsu"])){		
						$pole =$this->kategoriehodnotenia();
						$kat= $this->kategorie();
						return view::load('kategoriahodnotenia',array('kategoriahodnotenia'=>$pole, 'kategorie'=>$kat));
					} else {
						return view::load('error404', array());
					}
									
					
					break;
					
				case ($this->number_check2($action)):
					$_SESSION["idupravkathod"]=$_GET['action'];
					return $this->redirect('/kategoriahodnotenia/uprav');
					break;
				default:
					return view::load('error404', array());	
			}	
		}
		
		
		private function kategoriehodnotenia(){
			$mkathod = New mkathod();
			return $mkathod->kategoriehodnotenia();
		}
		private function kategorie(){
			$mkathod = New mkathod();
			return $mkathod->kategorie();
		}
		
		private  function odstran($id){
			$mkathod = New mkathod();
			$mkathod->odstran($id);
		}    

		private function pridaj($meno,$kat){
			$mkathod = New mkathod();
			$mkathod->pridaj($meno, $kat);
		}
}

?>